﻿<?php
class user extends spModel
{
  var $pk = "userid"; // 每个留言唯一的标志，可以称为主键
  var $table = "user"; // 数据表的名称
	var $verifier = array(
		"rules" => array(
			'username' => array(
				'notnull' => TRUE,
				'minlength' => 2,
				'maxlength' => 12,
			),
			
			'password' => array(
				'notnull' => TRUE,
				'minlength' => 2,
				'maxlength' => 12,
			),
		),
		"messages" => array(
			'username' => array(
				'notnull' => "用户名不能为空",
				'minlength' => "用户名不能少于3个字符",
				'maxlength' => "用户名不能大于20个字符"
				),
				
			'password' => array(
				'notnull' => "密码不能为空",
				'minlength' => "密码不能少于3个字符",
				'maxlength' => "密码不能大于20个字符"
				),
		)
	);
  
	
/**
	 * 这里我们建立一个成员函数来进行用户登录验证
	 *
	 * @param username    用户名
	 * @param password    密码，请注意，本例中使用了加密输入框，所以这里的$upass是经过MD5加密的字符串。
	 */
	public function userlogin($username, $password){ 
		$conditions = array(
			'username' => $username,
			'password' => md5($password),
		);
		if( $result = $this->find($conditions) ){ 

			spClass('spAcl')->set($result['acl']);
			$_SESSION["userinfo"] = $result;
			return true;
		}else{
			return false;
		}
	}
	/**
	 * 无权限提示及跳转
	 */
	public function acljump(){ 
		// 这里直接“借用”了spController.php的代码来进行无权限提示
		$url = spUrl("main","index");
		echo "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
			<script>function sptips(){alert(\"您没有权限进行此操作，请登录！\");location.href=\"{$url}\";}</script>
			</head><body onload=\"sptips()\"></body></html>";
		exit;
	}
	//按用户权限。。。
	function u_status()
	{
		switch ($_SESSION["userinfo"]["status"])
		{
			case 0:
				$value=array(1,2,5,10,15,20,30,60);
				return $value;
				break;
			case 1:
				$value=array(1);
				return $value;
				break;
			case 2:
				$value=array(2);
				return $value;
				break;
			case 3:
				$value=array(5);
				return $value;
				break;
			case 4:
				$value=array(10);
				return $value;
				break;
			case 5:
				$value=array(15);
				return $value;
				break;
			case 6:
				$value=array(20);
				return $value;
				break;
			case 7:
				$value=array(30);
				return $value;
				break;
			case 8:
				$value=array(60);
				return $value;
				break;			
		}
	}
}